package vues;

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;

import controleur.Horloge;
import evenements.EcouteurBarMenu;

public class IHM extends JFrame{
	
	private static final long serialVersionUID = 1L;
	private JPanel pan;
	private PanelGrille panGrille;
	private PanelDroite panDroite;
	private JMenuBar menubar;
	private JMenu simuMenu, robotMenu, feuMenu;
	private JMenuItem sauvegarder, charger, chargerMap, start,stop,quitter,creerRobot,creerFeu;
	
	public IHM(Horloge h){
		this.horloge = h;
		this.setIconImage(new ImageIcon(getClass().getResource("robot-haut.png")).getImage());
		this.setTitle("FireBot");
		this.setMinimumSize(new Dimension(600, 300));
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setSize(1150, 900);
		this.setLocationRelativeTo(null);
		this.pan = new JPanel(new BorderLayout());
		this.panGrille = new PanelGrille(this);
		this.panDroite = new PanelDroite(this);
		this.initMenuBar();
		this.pan.add(panGrille, BorderLayout.CENTER);
		this.pan.add(panDroite, BorderLayout.EAST);
		this.setContentPane(pan);
	}
	
	private void initMenuBar() {
		EcouteurBarMenu ecouteurMenu = new EcouteurBarMenu(this, this.horloge);
		menubar = new JMenuBar();
		simuMenu = new JMenu("Simulateur");
		robotMenu = new JMenu("Robots");
		feuMenu = new JMenu("Feux");
		sauvegarder = new JMenuItem("Sauvegarder la simulation");
		sauvegarder.addActionListener(ecouteurMenu);
		charger = new JMenuItem("Charger une simulation");
		charger.addActionListener(ecouteurMenu);
		chargerMap = new JMenuItem("Charger une map");
		chargerMap.addActionListener(ecouteurMenu);
		start = new JMenuItem("Lancer la simulation");
		start.addActionListener(ecouteurMenu);
		stop = new JMenuItem("Stopper la simulation");
		stop.addActionListener(ecouteurMenu);
		quitter = new JMenuItem("Quitter");
		quitter.addActionListener(ecouteurMenu);
		creerRobot = new JMenuItem("Créer un robot");
		creerRobot.addActionListener(ecouteurMenu);
		creerFeu = new JMenuItem("Créer un feu");
		creerFeu.addActionListener(ecouteurMenu);
		this.robotMenu.add(creerRobot);
		this.feuMenu.add(creerFeu);
		this.simuMenu.add(sauvegarder);
		this.simuMenu.add(charger);
		this.simuMenu.addSeparator();
		this.simuMenu.add(chargerMap);
		this.simuMenu.addSeparator();
		this.simuMenu.add(start);
		this.simuMenu.add(stop);
		this.simuMenu.addSeparator();
		this.simuMenu.add(quitter);
		this.menubar.add(simuMenu);
		this.menubar.add(robotMenu);
		this.menubar.add(feuMenu);
		this.setJMenuBar(menubar);
	}

	private Horloge horloge;
	
	public Horloge getHorloge() {
		return horloge;
	}
	
	public void setHorloge(Horloge h) {
		this.horloge = h;
	}

	public JPanel getPan(){
		return this.pan;
	}
	
	public void refresh(){
		this.panGrille.initGrilleV2();
		this.revalidate();
	}
	
	public PanelGrille getPanGrille() {
		return panGrille;
	}

	public PanelDroite getPanStats() {
		return panDroite;
	}
}